<template>
  <div>
    <BasicTable @register="registerTable" :searchInfo="searchInfo">
      <template #toolbar>
        <a-button type="primary" @click="handleCreate"> 指定商家</a-button>
      </template>
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
      </template>
    </BasicTable>
   <ShopSelectModal @register="registerShopSelectModal" @success="reloadTable"></ShopSelectModal>
  </div>
</template>
<script lang="ts" setup name="UseShopIndex">
import { reactive } from 'vue';
import { BasicTable, TableAction, ActionItem } from '@apps/antd-admin/src/components/Table';
import { useDrawer } from '@apps/antd-admin/src/components/drawer';
import { useBaseTable } from '@apps/antd-admin/src/hooks';

import { columns, searchFormSchema } from '../data/bag.data';
import { Api } from '../data/bag.api';
import ShopSelectModal from "./shop/ShopSelectModal.vue";
import {useModal} from "@apps/antd-admin/src/components/modal";
const [registerShopSelectModal, { openModal: openShopSelectModal }] = useModal();
const [registerDrawer, { openDrawer }] = useDrawer();
const { prefixCls, tableContext, handleDelete, handleSuccess, handlePost } = useBaseTable({
  designScope: 'airportGiveGoodsNum-template',
  tableProps: {
    //表格标题
    title: '优惠券使用范围',
    useSearchForm:false,
    //列表查询handler
    handlerName: 'sysCouponShopListHandler',
    //主键字段
    rowKey: 'couponShopId',
    //列表接口
    listUrl: Api.page,
    //删除接口
    delUrl: Api.remove,
    //列定义
    columns,
    //查询表单配置
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    //操作列配置
    actionColumn: {
      width: 120,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: 'right',
    },
  },
});

const [registerTable, { reload }, { rowSelection, hasSelectedRows }] = tableContext;

/**
 * 行内操作栏
 */
function getTableAction(record:any): ActionItem[] {
  return [

  ];
}

/**
 * 下拉操作栏
 */
function getDropDownAction(record): ActionItem[] {
  return [
    {
      label: '删除',
      popConfirm: {
        title: '是否确认删除',
        icon: 'ant-design:delete-outlined',
        confirm: handleDelete.bind(null, record),
      },
    },
  ];
}

function handleCreate() {
  let record = { couponId: searchInfo.couponId };
  openShopSelectModal(true, {
    record,
    isUpdate: false,
  });
}

function handleEdit(record: Recordable) {
  openDrawer(true, {
    record,
    isUpdate: true,
  });
}

const searchInfo = reactive<Recordable>({});

function setSearchInfoProps(couponId:any) {
  searchInfo.couponId = couponId;
}
function reloadTable(){
  reload();
}
defineExpose({
  setSearchInfoProps,
});
</script>
